﻿using System;
using System.ComponentModel.Composition.Hosting;
using System.Windows;
using IntoNails.Infrastructure;
using IntoNails.Infrastructure.Views.Behaviors;
using IntoNails.Modules.AuditTrail;
using IntoNails.Modules.CategoryManagement;
using IntoNails.Modules.CustomerManagement;
using IntoNails.Modules.StartUp;
using IntoNails.Modules.StatusBar;
using IntoNails.Modules.TicketManagement;
using IntoNails.Modules.UserManagement;
using Microsoft.Practices.Prism.MefExtensions;
using Microsoft.Practices.Prism.Regions;

namespace IntoNails
{
	/// <summary>
	/// Description of IntoNailsBootstrapper.
	/// </summary>
    [CLSCompliant(false)]
	public class IntoNailsBootstrapper : MefBootstrapper
	{
		protected override void ConfigureAggregateCatalog()
		{
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(IntoNailsBootstrapper).Assembly));
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(GlobalCommands).Assembly));
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(StartUpModule).Assembly));
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(TicketManagementModule).Assembly));
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(CustomerManagementModule).Assembly));
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(CategoryModule).Assembly));
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(UserManagementModule).Assembly));
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(StatusBarModule).Assembly));
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(AuditTrailModule).Assembly));
		}

        protected override DependencyObject CreateShell()
        {
            return this.Container.GetExportedValue<Shell>();
        }

        protected override void InitializeShell()
        {
            base.InitializeShell();

#if SILVERLIGHT
            Application.Current.RootVisual = (Shell)this.Shell;            
#else
            Application.Current.MainWindow = (Shell)this.Shell;
            Application.Current.MainWindow.Show();
#endif
        }
        
        protected override IRegionBehaviorFactory ConfigureDefaultRegionBehaviors()
        {
            var factory = base.ConfigureDefaultRegionBehaviors();

            // this behavior helps populating views into defined regions where they should belong to...
            factory.AddIfMissing("AutoPopulateExportedRegionBehavior", typeof(AutoPopulateExportedRegionBehavior));

            return factory;
        }
	}
}
